/*
    Project:        Home Power Control
    File:           HPCSensorValue.h
    Author:         christian@karunamusic.at
    Date:           12.2015
    Description:
 */

#ifndef HPCSENSORVALUE_H
#define HPCSENSORVALUE_H

#include <vector>
#include "HPCAlarmValue.h"


class HPCSensorValue : public HPCValue
{
public:
    /** \brief Constructor.
     */
    HPCSensorValue();
    /** \brief Constructor.
     *
     * \param val The value as string (char *).
     * \param vt The valuetpe.
     *
     */
    HPCSensorValue( const char* val, ValueType vt );
    /** \brief Copy Constructor.
     *
     * \param ref The object to copy.
     *
     */
    HPCSensorValue( HPCSensorValue& ref );
    /** \brief Destructor.
     */
    virtual ~HPCSensorValue();

    /** \brief Get he value from Min-Alarm-vector at position ndx.
     * The index is an argument of the HPCSensor::TSignalAlarm callback method!
     *
     * \param ndx The index of the value.
     * \return A pointer to the value or nullptr if index out of range.
     *
     */
    const HPCValue* Min( unsigned int ndx );
    /** \brief Get he value from Max-Alarm-vector at position ndx.
     * The index is an argument of the HPCSensor::TSignalAlarm callback method!
     *
     * \param ndx The index of the value.
     * \return A pointer to the value or nullptr if index out of range.
     *
     */
    const HPCValue* Max( unsigned int ndx );

    /** \brief Add upper and lower alarm to the SensorValue with the given id.
     * Can be called more than once to add alarms.
     *
     * \param Min The min-value as string or NULL if unused.
     * \param Max The max-value as string or NULL if unused.
     *
     */
    void addAlarm( const char* Min, const char* Max );

    /** \brief method to check if sensor is beyond limits.
     *
     * \return int 0 if no alarm, <0 if below limit, >0 if above limit (index of the fired alarm).
     */
    int isAlarm();

    /**< Assignment operators. */
    HPCSensorValue& operator= (bool v);
    HPCSensorValue& operator= (char v);
    HPCSensorValue& operator= (unsigned char v);
    HPCSensorValue& operator= (int v);
    HPCSensorValue& operator= (unsigned int v);
    HPCSensorValue& operator= (long v);
    HPCSensorValue& operator= (unsigned long v);
    HPCSensorValue& operator= (float v);
    HPCSensorValue& operator= (double v);
    HPCSensorValue& operator= (const std::string& v);

    /**< Copy operators. */
    HPCSensorValue& operator= (const HPCValue& v);
    HPCSensorValue& operator= (const HPCSensorValue& v);

private:
    std::vector<HPCAlarmValue *> m_Min;
    std::vector<HPCAlarmValue *> m_Max;
};

#endif // HPCSENSORVALUE_H
